﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Page = Entity.Page;
using BUL;

namespace PM
{
    public partial class HomeMaster : System.Web.UI.MasterPage
    {
        private PageBul bul = new PageBul();
        private NewsBul news = new NewsBul();

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadMenu();
            LoadTinNoibat();
        }

        public void LoadMenu()
        {
            var list1 = bul.Page_GetByPosition("2", "vi", 5);
            string strMenu = "<ul>";
            foreach (var menu1 in list1)
            {
                strMenu = strMenu + string.Format("<li><a href=\"{0}\">{1}</a>", menu1.Link, menu1.Name);
                var sublist1 = bul.Page_GetByLevel(menu1.Level, "vi", 10);
                if (sublist1.Count > 0)
                {
                    strMenu = strMenu + "<ul>";
                    foreach (var menu2 in sublist1)
                    {
                        strMenu = strMenu + string.Format("<li><a href=\"{0}\">{1}</a></li>", menu2.Link, menu2.Name);
                    }
                    strMenu = strMenu + "</ul>";
                }
                strMenu = strMenu + "</li>";
            }
            strMenu = strMenu + "</ul>";
            ltrUlTop.Text = strMenu;
        }

        private void LoadTinNoibat()
        {

            var listNews = news.News_GetByTop("5", "Check2=1", "Date desc");
            string strHotNews = "<ul id=\"featurednews\">";
            foreach (var newsitem in listNews)
            {
                string strLink = "/News/" + newsitem.GroupNewsId + "/" + newsitem.Id + "/" +
                                 Common.StringClass.NameToTag(newsitem.Name) + ".aspx";
                strHotNews = strHotNews +
                             string.Format(
                                 "<li><img src=\"{0}\" alt=\"\" width=\"600px\" height=\"280px\"/><div class=\"panel-overlay\">" +
                                 "<h2><a href=\"{3}\">{1}</h2></a>" +
                                 "<p>{2}</p>", newsitem.Image, newsitem.Name,
                                 newsitem.Content, strLink);
            }
            strHotNews = strHotNews + "</ul>";
            ltrHotnews.Text = strHotNews;
        }
    }
}